package com.hsxc.cdz.monitor.bean.second;

import com.hsxc.cdz.base.util.BytesUtil;
import com.hsxc.cdz.mgmt.GlobalManager;
import com.hsxc.cdz.monitor.FSM.CachePile;

/**
 * 充电时心跳上送报文
 * @author admin
 *
 */
public class ChargeHeartPileMsg extends SecMessage{

	private byte state;  //充电桩状态  //1:空闲中，2：充电中，3：故障中，4：维护中，5：满电占用中
                                  //6:未满电占用中    未满电占用中：在未充满电的情况下停止充电，但充电枪尚未拔出
	private byte plug;   //充电枪状态  1：未连接； 2：完全按揭 
	private byte park;   //停车位状态  1：未占用；2：已占用
	private CP56Time2a cp; //充电开始时间
	private int chargeTime; //充电 时长
	private int count;  ///电度表计数
	private Fault fault; //故障信息
	private Errcode errcode; //错误码
	private int electricity; //已充电量  倍率：0.01 
	private int soc;    //soc        倍率：0.01 
	private int voltage; //输出电压                倍率：0.01 
	private int current;  //输出电流         倍率：0.01 
	private int inputVoltage; //电压输入    倍率：0.01 
	
	public static final int length = 49;
	public static final int length_state = 1;
	public static final int length_plug = 1;
	public static final int length_park = 1;
	public static final int length_chargeTime= 2;
	public static final int length_count = 4;
	public static final int length_fault = 1;
	public static final int length_errcode = 1;
	public static final int length_electricity= 2;
	public static final int length_soc = 2;
	public static final int length_voltage = 4;
	public static final int length_current = 4;
	public static final int length_inputVoltage = 4;
	
	public static final int plug_false = 1;
	public static final int plug_true = 2;
	public static final int park_false = 1;
	public static final int park_true = 2;
	/*****************************************************************************/
	//重写父类方法
	@Override
	public byte[] getMessage() {
		return null;
	}

	@Override
	public void setMessage(byte[] data) {
		super.setMessage(data);
		int temp = SecMessage.length;
		this.state = data[temp];
		temp = temp + length_state;
		this.plug = data[temp];
		temp = temp+length_plug;
		this.park = data[temp];
		temp = temp+length_park;
		this.cp = new CP56Time2a(BytesUtil.getByte(temp, CP56Time2a.length, data));
		temp = temp+CP56Time2a.length;
		this.chargeTime = BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp, length_chargeTime, data));
		temp = temp+length_chargeTime;
		this.count = BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp, length_count, data));
		temp = temp+length_count;
		this.fault = new Fault(data[temp]);
		temp = temp +length_fault;
		this.errcode = new Errcode(data[temp]);
		temp = temp+length_errcode;
		this.electricity = BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp, length_electricity, data));
		temp = temp+length_electricity;
		this.soc = BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp,length_soc, data));
		temp = temp +length_soc;
		this.voltage =  BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp,length_voltage, data));
		temp = temp +length_voltage;
		this.current =  BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp,length_current, data));
		temp = temp +length_current;
		this.inputVoltage =  BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp,length_inputVoltage, data));
	}

	@Override
	public boolean execute() {
		CachePile pile = GlobalManager.pileManager.getPile(this.getPileNO());
		if(plug==plug_false){
			pile.setInserted(false);
		}else{
			pile.setInserted(true);
		}
		if(park==park_false){
			pile.setPark(false);
		}else{
			pile.setPark(true);
		}
		//pile.setFault(fault.getFault());
		String s = errcode.getErrcode();
		if(!s.equals(Fault.NOMAL)){
		//	pile.setFault(s);
		}
		
		return false;
	}

	/*****************************************************************************/
	//get() and set()
	public byte getState() {
		return state;
	}

	public void setState(byte state) {
		this.state = state;
	}

	public byte getPlug() {
		return plug;
	}

	public void setPlug(byte plug) {
		this.plug = plug;
	}

	public byte getPark() {
		return park;
	}

	public void setPark(byte park) {
		this.park = park;
	}

	public int getChargeTime() {
		return chargeTime;
	}

	public void setChargeTime(int chargeTime) {
		this.chargeTime = chargeTime;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
	
	public Fault getFault() {
		return fault;
	}

	public void setFault(Fault fault) {
		this.fault = fault;
	}

	public Errcode getErrcode() {
		return errcode;
	}

	public void setErrcode(Errcode errcode) {
		this.errcode = errcode;
	}

	public int getElectricity() {
		return electricity;
	}

	public void setElectricity(int electricity) {
		this.electricity = electricity;
	}

	public int getSoc() {
		return soc;
	}

	public void setSoc(int soc) {
		this.soc = soc;
	}

	public int getVoltage() {
		return voltage;
	}

	public void setVoltage(int voltage) {
		this.voltage = voltage;
	}

	public int getCurrent() {
		return current;
	}

	public void setCurrent(int current) {
		this.current = current;
	}

	public int getInputVoltage() {
		return inputVoltage;
	}

	public void setInputVoltage(int inputVoltage) {
		this.inputVoltage = inputVoltage;
	}

	public CP56Time2a getCp() {
		return cp;
	}

	public void setCp(CP56Time2a cp) {
		this.cp = cp;
	}
	
	
}
